package com.piz.service.common;

/**
 * @author prameetk.sharma
 *
 */
public class AuthenticationFailureException extends Exception {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public enum AuthenticationFailureReason {
        INVALID_USER_NAME,
        INVALID_PASSWORD,
        SYSTEM_ERROR
    }

    private AuthenticationFailureReason authenticationFailureReason;

    private String parameter;

    /**
     * @param reason
     */
    public AuthenticationFailureException(AuthenticationFailureReason reason) {
        this.authenticationFailureReason = reason;
    }

    /**
     * @param reason
     * @param parameter
     */
    public AuthenticationFailureException(AuthenticationFailureReason reason, String parameter) {
        this.authenticationFailureReason = reason;
        this.parameter = parameter;
    }

    /**
     * @return authenticationFailureReason
     */
    public AuthenticationFailureReason getAuthenticationFailureReason() {
        return authenticationFailureReason;
    }

    /**
     * @return parameter
     */
    public String getParameter() {
        return parameter;
    }

    /* (non-Javadoc)
     * @see java.lang.Throwable#getMessage()
     */
    public String getMessage() {

        if (authenticationFailureReason == AuthenticationFailureReason.INVALID_USER_NAME) {
            return "Authentication failed - Invalid user name provided." + parameter;
        }

        if (authenticationFailureReason == AuthenticationFailureReason.INVALID_PASSWORD) {
            return "Authentication failed - Invalid password provided.";
        }

        if (authenticationFailureReason == AuthenticationFailureReason.SYSTEM_ERROR) {
            return "Authentication failed - System error occurred. Please check server logs for more details.";
        }

        throw new RuntimeException("Un-identified authentication failure reason");

    }

}
